package com.hmdp.config;

import com.hmdp.utils.loginInterceptor;
import com.hmdp.utils.refreshInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;
import java.util.Locale;

/**
 * @Description
 * @Author Chrisn
 * @Date 2025/7/14
 */
@Configuration
public class MvcConfig implements WebMvcConfigurer {

    @Resource
    private StringRedisTemplate stringRedisTemplate;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //默认拦截所有请求
        //token刷新拦截器
        registry.addInterceptor(new refreshInterceptor(stringRedisTemplate)).addPathPatterns("/**").order(0);
        //登录拦截器
        registry.addInterceptor(new loginInterceptor()).excludePathPatterns(
                "/user/code",
                "/user/login",
                "/blog/hot",
                "/shop/**",
                "/shop-type/**",
                "/upload/**",
                "voucher/**"
        ).order(1);
    }
}
